<template>
  <div :class="['wrapper', classes]">
    <header class="main-header">
      <span class="logo-mini">
        <a href="/"><img src="/static/img/copilot-logo-white.svg" alt="Logo" class="img-responsive center-block logo"></a>
      </span>
      <!-- Header Navbar -->
      <nav class="navbar navbar-static-top" role="navigation">
        <!-- Sidebar toggle button-->
        <a href="javascript:;" class="sidebar-toggle" data-toggle="offcanvas" role="button">
          <span class="sr-only">显示导航栏</span>
        </a>
        <!-- Navbar Right Menu -->
        <div class="navbar-custom-menu">
          <ul class="nav navbar-nav">
<!--             
            <li class="dropdown messages-menu">
              <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-envelope-o"></i>
                <span class="label label-success">{{ userInfo.messages | count }}</span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">您有 {{ userInfo.messages | count }}条未读信息</li>
                <li v-if="userInfo.messages.length > 0">
                  <ul class="menu">
                    <li>
                      <a href="javascript:;">
                        <h4>
                          支持
                          <small>
                            <i class="fa fa-clock-o"></i> 5 mins</small>
                        </h4>
                        <p></p>
                      </a>
                    </li>
                  </ul>
                </li>
                <li class="footer" v-if="userInfo.messages.length > 0">
                  <a href="javascript:;">查看所有消息</a>
                </li>
              </ul>
            </li>

            <li class="dropdown notifications-menu">
              <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-bell-o"></i>
                <span class="label label-warning">{{ userInfo.notifications | count }}</span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">你有{{ userInfo.notifications | count }}条通知</li>
                <li v-if="userInfo.notifications.length > 0">
                  <ul class="menu">
                    <li>
                      <a href="javascript:;">
                        <i class="fa fa-users text-aqua"></i>5位新员工加入
                      </a>
                    </li>
                  </ul>
                </li>
                <li class="footer" v-if="userInfo.notifications.length > 0">
                  <a href="javascript:;">查看所有</a>
                </li>
              </ul>
            </li>

            <li class="dropdown tasks-menu">
              <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-flag-o"></i>
                <span class="label label-danger">{{ userInfo.tasks | count }} </span>
              </a>
              <ul class="dropdown-menu">
                <li class="header">您有{{ userInfo.tasks | count }}条待处理任务</li>
                <li v-if="userInfo.tasks.length > 0">
                  <ul class="menu">
                    <li>
                      <a href="javascript:;">
                        <h3>
                          Design some buttons
                          <small class="pull-right">20%</small>
                        </h3>
                        <div class="progress xs">
                          <div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only">20%完成</span>
                          </div>
                        </div>
                      </a>
                    </li>
                  </ul>
                </li>
                <li class="footer" v-if="userInfo.tasks.length > 0">
                  <a href="javascript:;">查看所有任务</a>
                </li>
              </ul>
            </li> -->

            <!-- User Account Menu -->
            <li class="dropdown user user-menu">
              <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                <!-- The user image in the navbar-->
                <!-- <img v-bind:src="demo.avatar" class="user-image" alt="User Image"> -->
                <!-- hidden-xs hides the username on small devices so only the image appears. -->
                <i class="fa fa-user fa-lg"></i>
                <span class="hidden-xs">{{ demo.displayName }}</span>
              </a>
            </li>
            <li>
              <a href="javascript:;" data-toggle="control-sidebar" @click="quit">
                <i class="fa fa-power-off"></i>
                <span class="hidden-xs">注销</span>
              </a>
            </li>
          </ul>
        </div>
        <div class="center-navbar">
          <span>人事管理系统</span>
        </div>
      </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <sidebar :display-name="demo.displayName" />

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          {{$route.name.toUpperCase() }}
          <small>{{ $route.meta.description }}</small>
        </h1>
        <ol class="breadcrumb">
          <li>
            <a href="javascript:;">
              <i class="fa fa-home"></i>主页</a>
          </li>
          <li class="active">{{$route.name.toUpperCase()}}</li>
        </ol>
      </section>

      <router-view></router-view>
    </div>
    <!-- /.content-wrapper -->

    <!-- Main Footer -->
    <footer class="main-footer">
      <strong>Copyright &copy; {{year}}
        <a href="javascript:;"></a>xtends</strong> All Rights Reserved.
    </footer>
  </div>
  <!-- ./wrapper -->
</template>

<script>
import faker from 'faker'
import { mapState } from 'vuex'
import config from '../config'
import Sidebar from './Sidebar'
import 'hideseek'

export default {
  name: 'Dash',
  components: {
    Sidebar
  },
  data: function () {
    return {
      // section: 'Dash',
      year: new Date().getFullYear(),
      classes: {
        fixed_layout: config.fixedLayout,
        hide_logo: config.hideLogoOnMobile
      },
      error: ''
    }
  },
  computed: {
    userInfo() {
      return {
        tasks: [],
        notifications: [],
        messages: []
      }
    },
    demo() {
      return {
        displayName: this.$store.state.user.username,
        avatar: faker.image.avatar(),
        email: faker.internet.email(),
        randomCard: faker.helpers.createCard()
      }
    }
  },
  methods: {
    changeloading() {
      this.$store.commit('TOGGLE_SEARCHING')
    },
    quit(){
      this.$store.commit('SET_USER', null)
      this.$store.commit('SET_GRAPH', null)
      this.$store.commit('SET_HANDLE', null)
      this.$store.commit('SET_SUBMIT', null)
      this.$store.commit('SET_SYSCONFIG',null)
      this.$http.headers.common['token'] = ''
      this.$http.headers.common['user'] = ''
      this.$http.headers.common['role'] = ''

      if (window.sessionStorage) {
        window.sessionStorage.removeItem('xLoginUser')
        window.sessionStorage.removeItem('xGraph')
        window.sessionStorage.removeItem('xhandle')
        window.sessionStorage.removeItem('xsubmit')
        window.sessionStorage.removeItem('sysconfig')
        window.sessionStorage.removeItem('departs')
      }

      this.$router.push('/login')
    }
  }
}
</script>

<style lang="scss">
.wrapper.fixed_layout {
  .main-header {
    position: fixed;
    width: 100%;
  }

  .content-wrapper {
    padding-top: 50px;
  }

  .main-sidebar {
    position: fixed;
    height: 100vh;
  }
}

.wrapper.hide_logo {
  @media (max-width: 767px) {
    .main-header .logo {
      display: none;
    }
  }
}

.logo-mini,
.logo-lg {
  text-align: left;

  img {
    padding: .4em !important;
  }
}

.logo-lg {
  img {
    display: -webkit-inline-box;
    width: 25%;
  }
}

.user-panel {
  height: 4em;
}

hr.visible-xs-block {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.17);
  height: 1px;
  border-color: transparent;
}

.center-navbar {
  display: block;
  text-align: left;
  color: white;
  padding: 5px;
  font-size: 28px;
  margin-left: 50px;
  margin-right: 300px;
}
</style>
